/**
 * Class that contains the functions for creating styles.
 * 
 * @constructor
 */
function Style() {
    "use strict";
    /**
     * Create a styĺe with the given fillColor.
     * 
     * @param {string} fill_color The desired colour (hex) that
     *  will fill the feature marker.
     * @returns A style with given fill colour.
     */
    function createStyle(fill_color) {
        var style = {
			graphicZIndex: 0,
            strokeColor: '#000000',
            strokeOpacity: 1,
            strokeWidth: 1,
            fillColor: fill_color,
            fillOpacity: 1,
        };

        return style;
    };

    /**
     * Creates a style map with rules for displaying different kinds
     * of locations with different styles. Uses rules and filters to achieve this.
     * Differentiates between waters, forests, cities and cultural locations.
     *
     * @param {integer} feature_length The size of the vector layer's feature array.
     * @param {object} map The map layer (for getZoom())
     * @returns An OpenLayers style map object
     */
    this.createStyleMap = function(feature_length, map) {
        var select_style,
            style,
            rule_waters,
            rule_forests,
            rule_cities,
            rule_culture,
            style_map;
        style = new OpenLayers.Style({
            pointRadius: '${radius}'
        }, {
            context: {
                // Change size of features depending on amount of features
                // Makes feature points slightly bigger on zoom in
                radius: function () {
                    var size = 5,
                        zoom = map.getZoom();
                    if (feature_length > 50) {
                        size = 4;
                    } else if (feature_length > 500) {
                        size = 3;
                    }
                    size += zoom / 2;
                    return size;
                }
            }
        });

        // The rules for the features
        rule_forests = new OpenLayers.Rule({
            filter: new Filters().createFilter('paikkatyyppialaryhmaKoodi', '11'),
            symbolizer: createStyle('#00cc00')
        });        
        rule_waters = new OpenLayers.Rule({
            filter: new Filters().createFilter('paikkatyyppialaryhmaKoodi', '12'),
            symbolizer: createStyle('#0099cc')
        });
        rule_cities = new OpenLayers.Rule({
            filter: new Filters().createFilter('paikkatyyppialaryhmaKoodi', '21'),
            symbolizer: createStyle('#cc0000')
        });
        rule_culture = new OpenLayers.Rule({
            filter: new Filters().createFilter('paikkatyyppialaryhmaKoodi', '22'),
            symbolizer: createStyle('#cc0000')
        });
        select_style = new OpenLayers.Style({
			graphicZIndex: 1,
			strokeColor: '#000000',
            strokeOpacity: 1,
            strokeWidth: 1,
            fillColor: '#f8ff13',
            fillOpacity: 1,
		});

        style.addRules([rule_waters, rule_forests, rule_cities, rule_culture]);

        style_map = new OpenLayers.StyleMap({
            'default': style,
            'select': select_style,
            'delete': new OpenLayers.Style({
                display: 'none'
            })
        });

        return style_map;
    };
}